package com.cuijq.ms.chaindesign.v1;

/**
 * @author by CuiJQ
 * @Classname HandlerChain
 * @Description HandlerChain Description
 * @Date 2021/5/29 10:19
 */
public class HandlerChain {

  private Handler head = null;
  private Handler tail = null;

  public void addHandler(Handler handler) {
    handler.setSuccessor(null);
    if (head == null) {
      head = handler;
      tail = handler;
      return;
    }
    tail.setSuccessor(handler);
    tail = handler;
  }

  public void handle() {
    if (head != null) {
      head.handle();
    }
  }
}
